#{extends '/main.html' /}
<div>
	<script type="text/javascript" src="@{'/public/js/jquery.form.js'}"></script>
	<div style="padding-left: 5px;margin-bottom: 5px;">
		<a href="javascript:history.go(-1);">&lt;&lt; 取消修改并返回列表页面</a>
	</div>
	<form action="@{manager.ShopItemController.modify}" method="post"
		enctype="multipart/form-data" id="addItemForm">
		<input type="hidden" name="itemId" value="${item.itemId}"/>
		<table id="modifyTable" cellspacing="0" cellpadding="0">
			<tr>
				<td align="center" colspan="2" style="color: red;" id="err">${error_msg}</td>
			</tr>
			<tr>
				<td>显示名称</td>
				<td><input type="text" name="itemName" size="50"
					value="${item.itemName}" /><font color="red">*</font></td>
			</tr>
			<tr>
				<td>商品图片</td>
				<td valign="bottom" title="如果需要修改请填写此空，否则请勿动">
					<div style="border: 1px solid #B8D0D6; padding: 2px;">
						<img alt="" src="${item.imagePath}" width="100" height="100"/>
					</div>
					<div style="display: inline; float: left">
						<span id="fileContainer" style="display: inline; float: left"><input
							type="radio" name="imageType" value="1" checked="checked" />网络图片<input
							type="radio" name="imageType" value="2" />本地图片<br /> <input
							type="text" name="netImage" id="fileInput" size="100" /> </span>
					</div>
				</td>
			</tr>
			<tr>
				<td>描述</td>
				<td><input type="text" name="description"
					value="${item.description}" /></td>
			</tr>
			<tr>
				<td>市场价格</td>
				<td><input type="text" name="marketPrice"
					value="${item.marketPrice}" /><font color="red">*</font></td>
			</tr>
			<tr>
				<td>销售价格</td>
				<td><input type="text" name="price" value="${item.price}" /><font
					color="red">*</font></td>
			</tr>
			<tr>
				<td>类型</td>
				<td><select name="type">
						<option value="1"  ${item.type=='1'?'selected':''}>男童装</option>
						<option value="2"  ${item.type=='2'?'selected':''}>女童装</option>
				</select> <font color="red">*</font></td>
			</tr>
			<tr>
				<td>详情地址</td>
				<td><input type="text" size="50" name="detailUrl" value="${item.detailUrl}" /><font
					color="red">*</font></td>
			</tr>
			<tr>
				<td></td>
				<td align="center"><input type="submit" value="修改" id="addBtn" /></td>
			</tr>
		</table>
	</form>
	<script type="text/javascript">
		var addTip = '${tip}';
		if (addTip.length > 0) {
			if (addTip == "success") {
				alert('添加成功');
			} else {
				alert(addTip);
			}
		}
		//表格样式
		$("#modifyTable").css("broder","1px solid #B8D0D6");
		$("#modifyTable td").css("border","1px solid #D0D0D0");
		
		$("#fileContainer :radio").click(function() {
			var typeRadio = $("#fileContainer :radio");
			$("#fileContainer")[0].removeChild($("#fileInput")[0]);
			var input = $(document.createElement("input"));
			input.attr("id", "fileInput");
			if (typeRadio[0].checked) {
				input.attr("type", "text");
				input.attr("name", "netImage");
				input.attr("size", "100");
			} else {
				input.attr("type", "file");
				input.attr("name", "imagePath");
			}
			$("#fileContainer").append(input);
		});

		$("#addItemForm tr td:first-child").css("textAlign", "right");
		$("#addItemForm tr td:last-child").css("textAlign", "left");
		$("#addItemForm tr td:last-child:first-child").css("marginRight", "5");
		$("#addItemForm").submit(
				function(e) {
					if ($("input[name='itemName']").val().length <= 0) {
						$("#err").text("请输入商品名称");
						return false;
					}
					var typeRadio = $("#fileContainer :radio");
					if (typeRadio[1].checked) {
						var file = $("input[name='imagePath']").val();
						if (file.length > 0) {
							var ext = file.substring(file.lastIndexOf('.') + 1)
									.toLowerCase();
							if (ext != 'jpg' && ext != 'jpeg' && ext != 'png'
									&& ext != 'bmp' && ext != 'gif') {
								$("#err").text("图片格式不正确，请选择一个有效的图片");
								return false;
							}
						}
					}
					var marketPrice = parseFloat($("input[name='marketPrice']")
							.val());
					if (isNaN(marketPrice)) {
						$("#err").text("市场价格不是一个有效的数字");
						return false;
					}
					var price = parseFloat($("input[name='price']").val());
					if (isNaN(price)) {
						$("#err").text("销售价格不是一个有效的数字");
						return false;
					}
					if (price > marketPrice) {
						$("#err").text("销售价格不能高于市场价格");
						return false;
					}
					if ($("input[name='detailUrl']").val().lenth <= 0) {
						$("#err").text("请输入商品查看详情淘宝网址");
						return false;
					}

					$("#err").text("");
					return true;
				});
	</script>
</div>